package tx.bj12320.util;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.guodu.gdpp.MySMProxy;
import com.guodu.gdpp.msg.MTMessage;
import com.guodu.util.Args;
import com.guodu.util.Cfg;

public class SmsUtils {
	protected static Log log = LogFactory.getLog(SmsUtils.class);
	public static boolean sendSms(String sellPhone, String smsContent){
		MySMProxy myProxy = null;
		try {
					// 获取配置文件中的参数。
			Args arg = new Cfg(new File(AppHelper.getWebAppPath()+"WEB-INF/classes/"+"config.xml").toURI().toString()).getArgs("gdpp");
			log.info(new File(AppHelper.getWebAppPath()+"WEB-INF/classes/"+"config.xml").toURI().toString());
					myProxy = new MySMProxy(arg);//产生代理
				/**参数说明：参数1：发送短信内容 参数2：发送手机号码 参数3：消息格式默认15 参数4：扩展号码*/
				MTMessage longmsg = new MTMessage(smsContent,sellPhone,15,"");
				myProxy.submitLongMsg(longmsg);

				log.info((new SimpleDateFormat("yyyyMMddHHmmss").format(new java.util.Date())+
					"---------->下行消息:"+longmsg.toString()));

		} catch (IOException e) {
			e.printStackTrace();
			return false;
		}finally{
			if(myProxy != null)
				myProxy.close();
		}
		return true;
	}
}
